package jf.collections.range;

import java.math.BigDecimal;
import java.util.Iterator;
import java.util.NoSuchElementException;

/**
 * @author ivanalx
 * @date 02.06.2009 14:47:53
 */
public class BigDecimalRangeIterator implements Iterator<BigDecimal> {
	private BigDecimal step;
	private BigDecimal to;
	private BigDecimal current;

	public BigDecimalRangeIterator(BigDecimal from, BigDecimal to, BigDecimal step) {
		this.step = step;
		this.to = to;
		current = from;
	}

	public BigDecimalRangeIterator(BigDecimal from, BigDecimal to) {
		this.step = new BigDecimal(1);
		this.to = to;
		current = from;
	}

	@Override
	public boolean hasNext() {
		return current.compareTo(to) <= 0;
	}

	@Override
	public BigDecimal next() {
		if (current.compareTo(to) > 0) {
			throw new NoSuchElementException();
		}
		BigDecimal tmp = current;
		current = current.add(step);
		return tmp;
	}

	@Override
	public void remove() {
		throw new UnsupportedOperationException();
	}
}
